package cn.maihe.elg.operation.centers.hymake.handler.service;

import cn.maihe.elg.operation.centers.hymake.auth.HyMakeCenterAuthConfig;
import cn.maihe.elg.operation.centers.hymake.config.HyMakeInfoConfig;
import cn.maihe.elg.operation.centers.hymake.dto.handler.vo.xm.XMBaseRespDTO;
import cn.maihe.elg.operation.centers.hymake.dto.handler.vo.xm.XMFilePushReqDTO;
import cn.maihe.elg.operation.centers.hymake.enums.HyMakeCheckResultEnum;
import cn.maihe.elg.operation.centers.hymake.enums.HyMakeRespCodeEnum;
import cn.maihe.elg.operation.centers.hymake.enums.XMChannelMethod;
import cn.maihe.elg.operation.centers.hymake.exception.HyMakeException;
import cn.maihe.elg.operation.centers.hymake.handler.HyMakeCenterTradeService;
import cn.maihe.elg.operation.centers.supports.CenterTradeContext;
import cn.maihe.elg.operation.centers.supports.annotation.CenterTradeService;
import cn.maihe.elg.operation.common.Constants;
import cn.maihe.elg.operation.config.ImageUploadConfig;
import cn.maihe.elg.operation.model.dto.InnerBaseResp;
import cn.maihe.elg.operation.model.enums.AcceptOrderStatus;
import cn.maihe.elg.operation.model.enums.AttachmentFileType;
import cn.maihe.elg.operation.model.enums.BidCustomerStatus;
import cn.maihe.elg.operation.model.enums.CenterNoEnum;
import cn.maihe.elg.operation.model.enums.CenterProviderEnum;
import cn.maihe.elg.operation.model.enums.CustomerAttachmentTypeEnum;
import cn.maihe.elg.operation.model.enums.InnerRespCode;
import cn.maihe.elg.operation.model.enums.NoticeTypeEnum;
import cn.maihe.elg.operation.model.enums.TradeType;
import cn.maihe.elg.operation.repository.entity.AcceptOrderInfoDO;
import cn.maihe.elg.operation.repository.entity.AcceptOrderInfoDOCondition;
import cn.maihe.elg.operation.repository.entity.BidCustomerDO;
import cn.maihe.elg.operation.repository.entity.CustomerAttachmentDO;
import cn.maihe.elg.operation.repository.entity.GuaranteeAttachmentInfoDO;
import cn.maihe.elg.operation.repository.entity.OrganizationDO;
import cn.maihe.elg.operation.repository.entity.OrganizationDOCondition;
import cn.maihe.elg.operation.repository.entity.SpdBankNotice;
import cn.maihe.elg.operation.repository.entity.SpdBankNoticeCondition;
import cn.maihe.elg.operation.service.business.BidCustomerService;
import cn.maihe.elg.operation.service.business.CustomerAttachmentService;
import cn.maihe.elg.operation.service.order.AcceptOrderInfoService;
import cn.maihe.elg.operation.service.order.GuaranteeAttachmentInfoService;
import cn.maihe.elg.operation.service.order.NoticeRetryInfoService;
import cn.maihe.elg.operation.service.order.SpdBankNoticeService;
import cn.maihe.elg.operation.service.system.impl.OrganizationServiceImpl;
import cn.maihe.elg.operation.supports.system.ElgResourceService;
import cn.maihe.elg.operation.utils.Base64Util;
import cn.maihe.elg.operation.utils.DateUtil;
import cn.maihe.elg.operation.utils.ElgLogger;
import cn.maihe.elg.operation.utils.IdGenerate;
import cn.maihe.elg.operation.utils.NR;
import cn.maihe.elg.operation.utils.OkHttpUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

/**
 * @Description 电子保函平台向出函机构（保险公司/银行）推送投保材料的下载地址
 * 文件类型名称 固定但不保证顺序
 * 投保材料
 * 电子申请单
 * 营业执照
 * 企业资质
 * 身份证正面
 * 身份证反面
 * @Author WJH
 * @Date 2022/04/01
 * 3.1.4、接收申请单盖章文件(文件)
 */
@CenterTradeService(
        provider = CenterProviderEnum.XIANMEN,
        centerNo = CenterNoEnum.XIAMEN,
        tradeType = TradeType.filePush,
        reqClass = XMFilePushReqDTO.class,
        respClass = XMBaseRespDTO.class
)
@Slf4j
public class XMFilePushService extends HyMakeCenterTradeService<XMFilePushReqDTO, XMBaseRespDTO> {

    @Resource
    private ElgResourceService elgResourceService;
    @Resource
    private AcceptOrderInfoService acceptOrderInfoService;
    @Resource
    private CustomerAttachmentService customerAttachmentService;
    @Resource
    private GuaranteeAttachmentInfoService guaranteeAttachmentInfoService;
    @Resource
    private ImageUploadConfig imageUploadConfig;
    @Resource
    private BidCustomerService bidCustomerService;

    @Resource
    OrganizationServiceImpl organizationService;

    @Resource
    private HyMakeInfoConfig hyMakeInfoConfig;

    @Resource
    private NoticeRetryInfoService noticeRetryInfoService;

    @Resource
    private SpdBankNoticeService spdBankNoticeService;

    public XMFilePushService(HyMakeInfoConfig centerInfosConfig) {
        super(centerInfosConfig);
    }

    @Resource(name = "resultNoticeHandleExecutor")
    private ThreadPoolTaskExecutor executor;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public XMBaseRespDTO processService(CenterTradeContext<XMFilePushReqDTO, XMBaseRespDTO> context) {
        XMFilePushReqDTO req = context.getReq();
        String appId = req.getAppId();
        String applyId = req.getApplyId();


        // 1. 根据投标人信息与工程担保保证人信息查询
        String guarantorName = req.getGuarantorName();
        String guarantorCreditCode = req.getGuarantorCreditCode();

        OrganizationDO organizationDO = organizationService.selectOne(OrganizationDOCondition.builder().andFullNameEq(guarantorName).andCreditCodeEq(guarantorCreditCode).build());

        if (organizationDO == null) {
            return XMBaseRespDTO.builder()
                    .success(false)
                    .errorCode(HyMakeCheckResultEnum.FAILURE.getCheckResult())
                    .errorDesc("工程担保保证人不存在")
                    .build();
        }

        AcceptOrderInfoDO acceptOrderInfo = acceptOrderInfoService.selectOne(AcceptOrderInfoDOCondition.builder().andCenterApplyIdEq(applyId).andOrgIdEq(organizationDO.getId()).build());
        if (acceptOrderInfo == null) {
            return XMBaseRespDTO.builder()
                    .success(false)
                    .errorCode(HyMakeCheckResultEnum.FAILURE.getCheckResult())
                    .errorDesc("保函订单信息不存在")
                    .build();
        }


        XMFilePushReqDTO req1 = context.getReq();

        Assert.notNull(acceptOrderInfo, "查无此投保单号");

//        if (AcceptOrderStatus.WAIT_SUBMIT_FIRST_TRAIL.getStatus() != acceptOrderInfo.getStatus() &&
//                AcceptOrderStatus.WAIT_SUBMIT_TUNE_UP.getStatus() != acceptOrderInfo.getStatus()) {
//            throw new RuntimeException("投保单号非承保已受理状态,无法推送投保材料地址");
//        }

        List<XMFilePushReqDTO.FileInfo> list = req.getFilesInfo();
        Map<String, String> fileKeys = req.getFileKeys();
        list.stream().forEach(fileInfo -> {
            try {
                fileInfo.setFileKey(fileKeys.get(fileInfo.getFileKey()));
                this.downloadFile(acceptOrderInfo, fileInfo);
            } catch (Exception e) {
                log.error("下载保存推送材料失败：{}", e.getMessage(), e);
                throw new RuntimeException("下载保存推送材料失败：" + e.getMessage(), e);
            }
        });

        AcceptOrderInfoDO update = AcceptOrderInfoDO.builder().id(acceptOrderInfo.getId())
                .status(AcceptOrderStatus.WAIT_PAY_CONFIRM.getStatus()).remark("投保材料地址推送处理成功，无需获取支付地址，状态更新未待支付确认")
                .build();
        acceptOrderInfoService.updateById(update);

        BidCustomerDO bidCustomer = new BidCustomerDO();
        bidCustomer.setId(acceptOrderInfo.getBidCustomerId());
        bidCustomer.setStatus(BidCustomerStatus.NORMAL.getStatus());
        bidCustomerService.updateById(bidCustomer);

        CompletableFuture.runAsync(() -> {
            try {
                Thread.sleep(3000L);
            } catch (InterruptedException e) {
                log.error("3.1.5、推送核保状态 延时失败"+e.getMessage(),e);
            }
            ElgLogger.info(log, log -> log.info("受理订单号[{}] >> 异步 3.1.5、推送核保状态", acceptOrderInfo.getAcceptOrderNo()));
            // 3.1.5 推送核保状态
            HyMakeCenterAuthConfig authConfig = hyMakeInfoConfig.getAuthConfig(CenterNoEnum.XIAMEN);
            HyMakeCenterAuthConfig hyMakeCenterAuthConfig = hyMakeInfoConfig.getAuthConfig(CenterNoEnum.XIAMEN);
            Map<String, Object> stringObjectMap = buildPushHBParam(authConfig, acceptOrderInfo, hyMakeCenterAuthConfig.getCenterInfo().getAppId());
            InnerBaseResp<String> innerBaseResp = OkHttpUtils.postDataByFormV2(authConfig.getCenterInfo().getUrl().trim() + XMChannelMethod.pushHBStatus.getMethod(), stringObjectMap,"3.1.5、推送核保状态");
            if (!innerBaseResp.getRespCode().getRespCode().equals(InnerRespCode.SUCCESS.getRespCode())) {
                noticeRetryInfoService.saveOrUpdateNoticeRetryInfo(NoticeTypeEnum.push_hb_status,
                        context.getCenterId(), context.getOrgId(),
                        acceptOrderInfo.getAcceptOrderNo(), stringObjectMap, null, innerBaseResp
                );
                ElgLogger.error(log, log -> log.error("受理订单号[{}] >> 异步3.1.5、推送核保状态,待下次通知：响应报文：{}", acceptOrderInfo.getAcceptOrderNo(), JSON.toJSONString(innerBaseResp)));
            }else {
                SpdBankNotice dbSpdBankNotice = spdBankNoticeService.selectOne(SpdBankNoticeCondition.builder().andAcceptOrderNoEq(acceptOrderInfo.getAcceptOrderNo()).build());
                if(Objects.nonNull(dbSpdBankNotice)) {
                    AcceptOrderInfoDO dbOrderInfo = acceptOrderInfoService.getByAcceptOrderNo(acceptOrderInfo.getAcceptOrderNo());
                    ElgLogger.info(log, log -> log.info("投保修改申请 受理订单号[{}] 订单状态[{}]", dbOrderInfo.getAcceptOrderNo(),dbOrderInfo.getStatus()));
                    acceptOrderInfoService.updateGuarantee(dbOrderInfo);
                }else {
                    ElgLogger.error(log, log -> log.error("银行流水不存在 受理订单号[{}] 订单状态[{}]", acceptOrderInfo.getAcceptOrderNo(),acceptOrderInfo.getStatus()));
                }
            }
        },executor);

        return XMBaseRespDTO.builder()
                .success(true)
                .build();
    }

    private InnerBaseResp buildInnerBaseResp(NR<String> stringNR, String apiString) {
        if (stringNR.isFail()) {
            // 需要测试时候才能确定返回结果是否为JSON格式
            log.error("通知异常:{}", stringNR.getErrorMessage());
            return InnerBaseResp.error("通知异常:" + stringNR.getErrorMessage());
        }

        JSONObject jsonObject = JSONObject.parseObject(stringNR.getData());
        if (!Boolean.TRUE.equals(jsonObject.get("success"))) {
            log.error("通知异常:{} ErrorCode:{}", jsonObject.get("errorDesc"), jsonObject.get("errorCode"));
            return InnerBaseResp.error("通知异常:" + jsonObject.get("errorDesc") + " ErrorCode: " + jsonObject.get("errorCode"));
        }

        log.info("通知成功:{}, 接口：{}", CenterNoEnum.XIAMEN, apiString);
        return InnerBaseResp.success(null, "");
    }

    /**
     * 厦门，生成3.1.5 接口请求参数
     *
     * @param acceptOrderInfo
     * @param appId
     * @return
     */
    private Map<String, Object> buildPushHBParam(HyMakeCenterAuthConfig hyMakeCenterAuthConfig , AcceptOrderInfoDO acceptOrderInfo, String appId) {

        Map<String, Object> reqBodyMap = new HashMap();

        reqBodyMap.put("APPID", appId);
        reqBodyMap.put("APPLY_ID", acceptOrderInfo.getCenterApplyId());

        reqBodyMap.put("AUDIT_STATUS", "1");

        // 保函创建时间
        reqBodyMap.put("AUDIT_TIME", DateUtil.formateDate(acceptOrderInfo.getGmtCreate(), DateUtil.FORMAT_DATETIME));


        reqBodyMap.put("APPLICATION_NO", acceptOrderInfo.getAcceptOrderNo());
        reqBodyMap.put("REASON", "1");

        BidCustomerDO bidCustomerDO = bidCustomerService.selectById(acceptOrderInfo.getBidCustomerId());

        String payUrl = elgResourceService.buildElgFrontUrl("/#/autoLogin?mobile=" + bidCustomerDO.getBidderCreditCode() + "&ordersn=" + acceptOrderInfo.getAcceptOrderNo());
        //todo 返回url待确认
        reqBodyMap.put("PAY_URL", payUrl);

        reqBodyMap.put("TIMESTAMP", DateUtil.getCurrentDate(DateUtil.FORMAT_DADETIME));

        String signature = hyMakeCenterAuthConfig.getHyMakeAuthorization().signature(reqBodyMap);


        reqBodyMap.put("SIGNATURE", signature);

        return reqBodyMap;
    }

    private void downloadFile(AcceptOrderInfoDO acceptOrderInfo, XMFilePushReqDTO.FileInfo fileInfo) throws Exception {
//        String fileTypeName = fileInfo.getFileName();
        String fileTypeName = fileInfo.getFileType();
        AttachmentFileType attachmentFileType = FileTypeNameEnum.toGuaranteeAttachmentFileType(fileTypeName);
        CustomerAttachmentTypeEnum customerAttachmentTypeEnum = FileTypeNameEnum.toCustomerAttachmentFileType(fileTypeName);
        if (attachmentFileType != null) {
            this.saveOrUpdateGuaranteeAttachInfo(attachmentFileType, acceptOrderInfo, fileInfo);
        } else if (customerAttachmentTypeEnum != null) {
            this.saveOrUpdateCustomerAttachInfo(customerAttachmentTypeEnum, acceptOrderInfo, fileInfo);
        }

    }

    private void saveOrUpdateCustomerAttachInfo(CustomerAttachmentTypeEnum customerAttachmentType, AcceptOrderInfoDO acceptOrderInfo, XMFilePushReqDTO.FileInfo fileInfo) throws Exception {
        String md5Value = fileInfo.getFileMD5();
        String fileName = fileInfo.getFileName();
        String fileType = fileInfo.getFileType();
        byte[] file = Base64Util.encode2Byte(fileInfo.getFileKey());

        Long bidCustomerId = acceptOrderInfo.getBidCustomerId();
        CustomerAttachmentDO customerAttachment = customerAttachmentService.getCustomerAttachment(bidCustomerId, customerAttachmentType);
        if (customerAttachment == null) {
            //todo:alan 不确定返回的文件后缀名 + "." + fileType
            Path tmpPath = elgResourceService.byte2LocalFile(file, fileName);
//            String relativePath = elgResourceService.transferAndSaveFile(tmpPath, "ofd", bidCustomerId.toString(), fileInfo.getFileTypeName());
            String relativePath = UUID.randomUUID().toString() + "." + elgResourceService.getFileType(tmpPath);
            Path registerDir = Paths.get(imageUploadConfig.getPath(), Constants.REGIST_IMAGE_PATH);
            if (Files.notExists(registerDir)) {
                Files.createDirectories(registerDir);
            }
            Path registerImg = registerDir.resolve(relativePath);
            Files.copy(tmpPath, registerImg, StandardCopyOption.REPLACE_EXISTING);

            Files.deleteIfExists(tmpPath);

            customerAttachment = new CustomerAttachmentDO();
            customerAttachment.setId(IdGenerate.getId());
            customerAttachment.setBidderId(bidCustomerId);
            customerAttachment.setAttachType(customerAttachmentType.getType());
            customerAttachment.setAttachPath(relativePath);
            customerAttachment.setAttachFileName(relativePath);
            customerAttachment.setFileMd5(md5Value);
            // todo 文件为：文件流 因此没有URL地址
//            customerAttachment.setFileUrl(fileUrl);

            customerAttachmentService.insert(customerAttachment);
        } else if (!md5Value.equalsIgnoreCase(customerAttachment.getFileMd5())) {
//            Path tmpPath = elgResourceService.downloadByURL(fileUrl);
            //todo:alan 不确定返回的文件后缀名 + "." + fileType
            Path tmpPath = elgResourceService.byte2LocalFile(file, fileName);
//            String relativePath = elgResourceService.transferAndSaveFile(tmpPath, "ofd", bidCustomerId.toString(), fileInfo.getFileTypeName());
            String relativePath = UUID.randomUUID().toString() + "." + elgResourceService.getFileType(tmpPath);
            Path registerDir = Paths.get(imageUploadConfig.getPath(), Constants.REGIST_IMAGE_PATH);
            if (Files.notExists(registerDir)) {
                Files.createDirectories(registerDir);
            }
            Path registerImg = registerDir.resolve(relativePath);
            Files.copy(tmpPath, registerImg, StandardCopyOption.REPLACE_EXISTING);

            Files.deleteIfExists(tmpPath);


            customerAttachment.setBidderId(bidCustomerId);
            customerAttachment.setAttachType(customerAttachmentType.getType());
            customerAttachment.setAttachPath(relativePath);
            customerAttachment.setAttachFileName(relativePath);
            customerAttachment.setFileMd5(md5Value);

            // todo 文件为：文件流 因此没有URL地址
//            customerAttachment.setFileUrl(fileUrl);

            customerAttachmentService.updateById(customerAttachment);
        }

    }

    private void saveOrUpdateGuaranteeAttachInfo(AttachmentFileType attachmentFileType, AcceptOrderInfoDO acceptOrderInfo, XMFilePushReqDTO.FileInfo fileInfo) throws Exception {
        String md5Value = fileInfo.getFileMD5();

        String fileName = fileInfo.getFileName();
        String fileType = fileInfo.getFileType();
        byte[] file = Base64Util.encode2Byte(fileInfo.getFileKey());
        String acceptOrderNo = acceptOrderInfo.getAcceptOrderNo();
        GuaranteeAttachmentInfoDO guaranteeAttachmentInfo = guaranteeAttachmentInfoService.getTypeAttachmentByAcceptOrderNo(acceptOrderNo, attachmentFileType);
        if (guaranteeAttachmentInfo == null) {
            //todo:alan 不确定返回的文件后缀名 + "." + fileType
            Path tmpPath = elgResourceService.byte2LocalFile(file, fileName);
//            Path tmpPath = elgResourceService.downloadByURL(fileUrl);
            String relativePath = elgResourceService.transferAndSaveFile(tmpPath, "ofd", acceptOrderNo, fileInfo.getFileName());
            Files.deleteIfExists(tmpPath);

            guaranteeAttachmentInfo = new GuaranteeAttachmentInfoDO();
            guaranteeAttachmentInfo.setId(IdGenerate.getId());
            guaranteeAttachmentInfo.setCenterId(acceptOrderInfo.getCenterId());
            guaranteeAttachmentInfo.setOrgId(acceptOrderInfo.getOrgId());
            guaranteeAttachmentInfo.setAcceptOrderNo(acceptOrderInfo.getAcceptOrderNo());
            guaranteeAttachmentInfo.setType(attachmentFileType.getType());
            guaranteeAttachmentInfo.setFileName(fileInfo.getFileName());
            guaranteeAttachmentInfo.setFileType(fileInfo.getFileType());
            guaranteeAttachmentInfo.setFileMd5(md5Value);
            guaranteeAttachmentInfo.setFilePath(relativePath);
            guaranteeAttachmentInfo.setRemark("新增" + attachmentFileType.getDesc());

            // todo 文件为：文件流 因此没有URL地址
            //guaranteeAttachmentInfo.setFileUrl(fileInfo.getUrl());

            guaranteeAttachmentInfoService.insert(guaranteeAttachmentInfo);
        } else if (!md5Value.equalsIgnoreCase(guaranteeAttachmentInfo.getFileMd5())) {
            //todo:alan 不确定返回的文件后缀名 + "." + fileType
            Path tmpPath = elgResourceService.byte2LocalFile(file, fileName);
//            Path tmpPath = elgResourceService.downloadByURL(fileUrl);
            String relativePath = elgResourceService.transferAndSaveFile(tmpPath, "ofd", acceptOrderNo, fileInfo.getFileName());
            Files.deleteIfExists(tmpPath);

            guaranteeAttachmentInfo.setCenterId(acceptOrderInfo.getCenterId());
            guaranteeAttachmentInfo.setOrgId(acceptOrderInfo.getOrgId());
            guaranteeAttachmentInfo.setAcceptOrderNo(acceptOrderInfo.getAcceptOrderNo());
            guaranteeAttachmentInfo.setType(attachmentFileType.getType());
            guaranteeAttachmentInfo.setFileName(fileInfo.getFileName());
            guaranteeAttachmentInfo.setFileType(fileInfo.getFileType());
            guaranteeAttachmentInfo.setFileMd5(md5Value);
            guaranteeAttachmentInfo.setFilePath(relativePath);
            guaranteeAttachmentInfo.setRemark("更新" + attachmentFileType.getDesc());
            //// todo 文件为：文件流 因此没有URL地址
//            guaranteeAttachmentInfo.setFileUrl(fileInfo.getUrl());

            guaranteeAttachmentInfoService.updateById(guaranteeAttachmentInfo);
        }

    }


    @Override
    protected XMFilePushReqDTO buildReq(Map<String, Object> clearParams) {
        try {
            String jsonString = JSONObject.toJSONString(clearParams);
            String clearString = jsonString.replace("\\\"", "\"")
                    .replace("\"[", "[")
                    .replace("]\"", "]")
                    .replace("\"{", "{")
                    .replace("}\"", "}");
            return JSONObject.parseObject(clearString, this.reqClass);
        } catch (Exception e) {
            throw HyMakeException.of(HyMakeRespCodeEnum.FAILURE, "反序列化异常", e);
        }
    }

    public static enum FileTypeNameEnum {
        TYPE01("投保材料"),
        TYPE02("电子申请单"),
        TYPE03("营业执照"),
        //        TYPE04("企业资质"),
        TYPE04("资质证书"),
        TYPE05("身份证正面"),
        TYPE06("身份证反面"),
        TYPE15("电子申请单原文件"),

        TYPE21("ORDER"),
        TYPE22("ORDER_PDF"),
        ;

        FileTypeNameEnum(String fileTypeName) {
            this.fileTypeName = fileTypeName;
        }

        private String fileTypeName;

        public String getFileTypeName() {
            return fileTypeName;
        }

        /**
         * 是否保存到订单附件表
         */
        public static AttachmentFileType toGuaranteeAttachmentFileType(String fileTypeName) {
            if (TYPE01.fileTypeName.equals(fileTypeName)) {
                //投保材料
                return AttachmentFileType.TYPE_13;
            } else if (TYPE02.fileTypeName.equals(fileTypeName)) {
                //申请书pdf文件 客户已签章推送
                return AttachmentFileType.TYPE_11;
            } else if (TYPE15.fileTypeName.equals(fileTypeName)) {
                //申请书文件edc 客户已签章推送
                return AttachmentFileType.TYPE_15;
            } else if (TYPE21.fileTypeName.equals(fileTypeName)) {
                //申请书文件edc 客户已签章推送
                return AttachmentFileType.TYPE_15;
            } else if (TYPE22.fileTypeName.equals(fileTypeName)) {
                //申请书pdf文件 客户已签章推送
                return AttachmentFileType.TYPE_11;
            }

            return null;
        }

        /**
         * 是否保存到订单附件表
         */
        public static CustomerAttachmentTypeEnum toCustomerAttachmentFileType(String fileTypeName) {
            if (TYPE03.fileTypeName.equals(fileTypeName)) {
                return CustomerAttachmentTypeEnum.TYPE_0;
            } else if (TYPE04.fileTypeName.equals(fileTypeName)) {
                return CustomerAttachmentTypeEnum.TYPE_7;
            } else if (TYPE05.fileTypeName.equals(fileTypeName)) {
                return CustomerAttachmentTypeEnum.TYPE_3;
            } else if (TYPE06.fileTypeName.equals(fileTypeName)) {
                return CustomerAttachmentTypeEnum.TYPE_2;
            }
            return null;
        }
    }


}

